package seqlist.leetcode;

public class Leetcode0204 {
    public ListNode1 partition(ListNode1 head, int x) {
        if (head==null||head.next==null){
            return head;
        }

        ListNode1 smallHead = new ListNode1(x);
        ListNode1 smallTail = smallHead;
        ListNode1 bighead = new ListNode1(x);
        ListNode1 bigTail =bighead;
        while (head!=null){
            if (head.val<x){
                smallTail.next=head;
                smallTail=head;
            }else {
                bigTail.next=head;
                bigTail=head;
            }
            head=head.next;
        }
        bigTail.next=null;
        smallTail.next=bighead.next;
        return smallHead.next;
    }
}
